home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4720 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  55 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Unable to check calloc`s
  5. Date: Tue, 06 Feb 96 15:23:18 GMT
  6. Organization: none
  7. Message-ID: <823620198snz@genesis.demon.co.uk>
  8. References: <4f2l8a$c98@gail.ripco.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4f2l8a$c98@gail.ripco.com> mambuhl@ripco.com "Martin Ambuhl" writes:
  15.  
  16. ...
  17.  
  18. >5) Hard coding constant values is usually a mistake:
  19. >    #include <stdlib.h>
  20. >    #define ARRAYSIZE   9
  21. >    {
  22. >        float **x;
  23. >        if (x = malloc(ARRAYSIZE*sizeof(float *))) == 0)
  24.             ^
  25. You need another ( here
  26.  
  27. >            exit(EXIT_FAILURE);
  28. >    }
  29.  
  30. And that is usually better written as:
  31.  
  32.     #include <stdlib.h>
  33.     #define ARRAYSIZE   9
  34.     {
  35.         float **x;
  36.         if (x = malloc(ARRAYSIZE*sizeof(*x))) == 0)
  37.             exit(EXIT_FAILURE);
  38.     }
  39.  
  40. or possibly:
  41.  
  42.     #include <stdlib.h>
  43.     #define ARRAYSIZE   9
  44.     {
  45.         float **x = malloc(ARRAYSIZE*sizeof(*x));
  46.         if (x == NULL)
  47.             exit(EXIT_FAILURE);
  48.     }
  49.  
  50. -- 
  51. -----------------------------------------
  52. Lawrence Kirby | fred@genesis.demon.co.uk
  53. Wilts, England | 70734.126@compuserve.com
  54. -----------------------------------------
  55.